<template>
  <div>
    <el-form ref="profileForm" label-position="top" :model="users" size="small">
      <el-form-item label="用户名：" prop="username">
        <el-input :value="user.username" disabled />
      </el-form-item>
      <el-form-item label="昵称：" prop="name">
        <el-input v-model="user.name" />
      </el-form-item>
      <el-form-item label="个性签名：" prop="sign">
        <el-input v-model="user.sign" :rows="5" type="textarea" maxlength="255" show-word-limit />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="updateProfile">保 存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

import axios from "axios";

export default {
  name: 'RProfile',
  props: ['user'],
  data() {
    return {
      users: {
        name: '',
        sign: ''
      },
    }

  },
  methods: {
    updateProfile() {
      let jwtToken = localStorage.getItem('jwtToken');
          axios.get('/api/users/updateInfo',
            {
              params: {name:this.user.name,sign:this.user.sign}, headers: {jwtToken: jwtToken}
            }).then(result => {
            if (result.data.code === 200) {
              if (result.data.data > 0) {
                this.$message({
                  showClose: true,
                  message: '修改成功！',
                  type: 'success',
                  duration: 2000
                });
              }
              this.users = {};
            }else {
              this.$message({
                showClose: true,
                message: '修改失败！',
                type: 'warning',
                duration:2000
              });
            }
          }).catch(e=>{
            this.$message({
              showClose: true,
              message: '服务器去火星了!',
              type: 'warning',
              duration:2000
            });
          })
        }
  }
}
</script>

<style lang="scss">

</style>
